package com.bolt.auth.admin.api.sys.dto.converter;


import com.bolt.auth.admin.api.sys.dto.DictDetailDTO;
import com.bolt.auth.admin.api.sys.entity.DictDetailEntity;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class DictDetailConverter {
    private DictDetailConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param detail DO对象
     * @return DTO对象
     */
    public static DictDetailDTO toDTO(DictDetailEntity detail) {
        if (Objects.isNull(detail)) {
            return null;
        }
        DictDetailDTO result = new DictDetailDTO();
        result.setId(detail.getId());
        result.setDictId(detail.getDictId());
        result.setLabel(detail.getLabel());
        result.setValue(detail.getValue());
        result.setDictSort(detail.getDictSort());
        result.setVersionNO(detail.getVersionNO());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param detail DO对象
     * @return VO对象
     */
    public static DictDetailEntity toEntity(DictDetailDTO detail) {
        if (Objects.isNull(detail)) {
            return null;
        }
        DictDetailEntity result = new DictDetailEntity();
        result.setId(detail.getId());
        result.setDictId(detail.getDictId());
        result.setLabel(detail.getLabel());
        result.setValue(detail.getValue());
        result.setDictSort(detail.getDictSort());
        result.setVersionNO(detail.getVersionNO());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param detail DO对象
     * @return VO对象
     */
    public static DictDetailEntity toEntity(DictDetailEntity result, DictDetailDTO detail) {
        if (Objects.isNull(detail)) {
            return null;
        }
        result.setDictId(detail.getDictId());
        result.setLabel(detail.getLabel());
        result.setValue(detail.getValue());
        result.setDictSort(detail.getDictSort());
        result.setVersionNO(detail.getVersionNO());
// TODO
        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param detailList Entity集合对象
     * @return DTO对象
     */
    public static List <DictDetailDTO> toDTO(List <DictDetailEntity> detailList) {
        if (Objects.isNull(detailList)) {
            return null;
        }
        return detailList.stream().map(DictDetailConverter::toDTO).collect(Collectors.toList());
    }

}
